package com.ywj.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorDemo2 {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("money");
        c.add("study");
        c.add("honor");
        c.add("happy");

        Iterator<String> it = c.iterator();
        while (it.hasNext()) {
            String s = it.next();
            if ("study".equals(s)) {
                //报错java.util.ConcurrentModificationException
//                c.remove(s);
                //使用迭代器删除。指向谁,那么此时就删除谁.
                it.remove();
            }
        }
        System.out.println(c);

    }
}
